<template>
  <el-form :model="optForm" label-width="150px" :rules="optFormRules" ref="optForm">
    <el-form-item label="结果" prop="Jieguo">
      <el-radio-group v-model="optForm.Jieguo" @change="changeJieguo">
        <el-radio label="同意">同意</el-radio>
        <el-radio label="不同意">不同意</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="意见" prop="Yijian">
      <el-input v-model="optForm.Yijian" auto-complete="off" type="textarea" :rows="4" style="width:800px" ></el-input>
    </el-form-item>
    <el-form-item label="提交用户选择：" prop="SelectUser" v-if="showSelectUser">
      <el-radio-group v-model="optForm.SelectUser" style="width: 100%;padding-top:30px">
      <el-table :data="myhouxuanren" highlight-current-row v-loading="listLoading" style="width: 100%;">
        <el-table-column prop="Description" label="下一步工作描述" width="300">
        </el-table-column>
        <el-table-column label="候选用户">
          <template slot-scope="scope">
            <el-radio v-for="item in scope.row.Users" :label="item.UserName" :key="item.UserName">{{item.TrueName}}</el-radio>
          </template>
        </el-table-column>
      </el-table>
      </el-radio-group>
    </el-form-item>
    <el-button type="primary" @click.native="optFormSubmit" :loading="optFormLoading" style="margin-left:150px">提交</el-button>
  </el-form>
</template>
<script>
export default {
  components: {
  },
  props: {
    myhouxuanren: {
      type: Array
    }
  },
  data () {
    return {
      optFormRules: {
        Jieguo: [
          { required: true, message: '请选择处理结果', trigger: 'blur' }
        ],
        SelectUser: [
          { required: true, message: '请选择用户', trigger: 'blur' }
        ]
      },
      optForm: {},
      optFormLoading: false,
      showSelectUser: false,
      listLoading: false
    }
  },
  methods: {
    changeJieguo: function () {
      if (this.optForm.Jieguo === '同意') {
        this.showSelectUser = true
      } else {
        this.showSelectUser = false
      }
    },
    optFormSubmit: function () {
      var _this = this
      this.$refs.optForm.validate((valid) => {
        if (valid) {
          console.log('意见内容:' + this.optForm.Yijian)
          if (this.optForm.Jieguo === '不同意' && (this.optForm.Yijian === undefined || this.optForm.Yijian.trim() === '')) {
            this.$alert('不同意请填写具体意见', '提示', {
              confirmButtonText: '确定',
              type: 'warning'
            })
            return
          }
          _this.optFormLoading = true
          let para = {
            id: this.$route.params.id,
            jieguo: this.optForm.Jieguo,
            yijian: this.optForm.Yijian,
            houxuanren: this.optForm.SelectUser
          }
          this.$http.post(`/shenghuohui/unittijiao`, para).then(function (response) {
            console.log(response.data.IsSuccess)
            if (response.data.IsSuccess === true) {
              _this.$message({
                message: '提交成功',
                type: 'success'
              })
              _this.$refs['optForm'].resetFields()
              _this.optFormLoading = false
              _this.$emit('refreshevent')
            } else {
              console.log('提交失败:' + response.data.Msg)
              _this.$message({
                message: '提交失败:' + response.data.Msg,
                type: 'error'
              })
              _this.optFormLoading = false
            }
          }).catch(function (error) {
            console.log(error)
            _this.$message({
              message: '提交失败:' + error,
              type: 'error'
            })
            _this.optFormLoading = false
          })
        }
      })
    }
  },
  mounted () {
  }
}
</script>
<style scoped>
</style>
